/**
 * Copyright By Grandsoft Company Limited.  
 * 2013-6-13 上午11:30:05
 */
package com.glodon.ggzy.jypt.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.glodon.ggzy.core.utils.PageSearchModel;
import com.glodon.ggzy.fwpt.service.IJsgcProjectService;

/**
 * 
 * 投标人控制类
 * @author zhangxj
 * @date 2013-6-12
 *
 */
@Controller
public class TbrController {

	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private IJsgcProjectService jsgcProjectService;

	/**
	 * 
	 * 投标人-主页
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/tbr_index")
	public String tbrIndexEnter(Model model) {
		return "/jypt/tbr_index";
	}

	/**
	 * 企业资质
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/tbr_ent_qual")
	public String tbrEntQual(Model model) {
		return "/jypt/tbr_ent_qual";
	}

	/**
	 * 基本信息
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/tbr_base_info")
	public String tbrBaseInfo(Model model) {
		return "/jypt/tbr_base_info";
	}

	/**
	 * 公开招标
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/tbr_gkzb")
	public String publicBiddingEnter(Model model) {
		return "/jypt/tbr_gkzb";
	}

	/**
	 * 公开招标:加载数据
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/load_tbr_gkzb_data")
	public void loadPublicBiddingData(Model model, int rows, int page, String searchText, HttpServletResponse response) {
		PageSearchModel qm = new PageSearchModel();
		qm.setPageNo(page);
		qm.setPageSize(rows);

		if (StringUtils.isNotEmpty(searchText)) {
			try {
				String[] params = new String[2];
				params[0] = "%" + URLDecoder.decode(searchText, "UTF-8") + "%";
				params[1] = "%" + URLDecoder.decode(searchText, "UTF-8") + "%";
				qm.setParams(params);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}

		/**
		Page queryPage = jsgcProjectService.queryPage(qm);
		List<JsgcProject> prjList = (List<JsgcProject>) queryPage.getResult();
		List<PublicBiddingVO> peList = new ArrayList<PublicBiddingVO>();
		for (int i = 0; i < prjList.size(); i++) {
			PublicBiddingVO pe = new PublicBiddingVO();
			pe.setBidNoticeName("标段一：" + prjList.get(i).getGgUrlname() + "</br>标段二：" + prjList.get(i).getGgUrlname());
			pe.setPackageType(prjList.get(i).getPrjType());
			pe.setBidNoticeCode(prjList.get(i).getPrjNo());
			pe.setEnrollEndTime(prjList.get(i).getGgEndtime());
			pe.setProjectName(prjList.get(i).getPrjName());
			if (i / 3 == 0) {
				pe.setEnrollStatus("false");
			} else {
				pe.setEnrollStatus("true");
			}
			pe.setOperation("我要报名");
			peList.add(pe);
		}
		queryPage.setResult(peList);
		**/
		String jsonStr = "";
		try {
			//jsonStr = JsonUtils.toJsonStr(queryPage);
			response.getWriter().write(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 邀请招标
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/invite_bidding_enter")
	public String inviteBidding(Model model) {
		return "/jypt/invite_bidding_enter";
	}

	/**
	 * 公开招标:加载数据
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/load_invite_bidding_enter_data")
	public void loadInviteEnterData(Model model, int rows, int page, HttpServletResponse response) {
		PageSearchModel qm = new PageSearchModel();
		qm.setPageNo(page);
		qm.setPageSize(rows);
		/**
		Page queryPage = jsgcProjectService.queryPage(qm);
		List<JsgcProject> projectList = (List<JsgcProject>) queryPage.getResult();
		List<PublicBiddingVO> peList = new ArrayList<PublicBiddingVO>();
		for (JsgcProject project : projectList) {
			PublicBiddingVO pe = new PublicBiddingVO();
			pe.setBidNoticeName("<font color=blue>北辰路3号公共租赁住房项目施工招标公告</font><br>报名时间：2013-5-12 9:00:00");
			pe.setBidNoticeCode("公告编号:JSCD20312-32 报名截止时间:2013-4-31 9:00:00");

			pe.setPackageType("施工");
			pe.setEnrollEndTime("2013-4-31 9:00:00");

			pe.setEnrollStatus("已报名");
			pe.setOperation(" <a href='#'><font color=blue>拒绝邀请</font></a>  <a href='#'>拒绝邀请</a>");

			peList.add(pe);
		}
		queryPage.setResult(peList);
		**/
		String jsonStr = "";
		try {
			//jsonStr = JsonUtils.toJsonStr(queryPage);
			response.getWriter().write(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 已报名标段：enrollpackage
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/tbr_ybmbd")
	public String enrollPackage(Model model) {
		return "/jypt/tbr_ybmbd";
	}

	@RequestMapping("/jypt/load_tbr_ybmdb_data")
	public void loadEnrollPackageEnter(Model model, int rows, int page, HttpServletResponse response) {
		PageSearchModel qm = new PageSearchModel();
		qm.setPageNo(page);
		qm.setPageSize(rows);
		/**
		Page queryPage = jsgcProjectService.queryPage(qm);
		List<JsgcProject> projectList = (List<JsgcProject>) queryPage.getResult();
		List<PublicBiddingVO> peList = new ArrayList<PublicBiddingVO>();
		for (JsgcProject project : projectList) {
			PublicBiddingVO pe = new PublicBiddingVO();
			pe.setBidNoticeName("标段一：" + project.getPrjName() + "<br>标段二：" + project.getPrjName());
			pe.setProjectName(project.getPrjName());
			pe.setBidNoticeCode(project.getPrjNo());

			pe.setPackageType("<a href='#'><font color=blue>招标文件</font></a> <br><a href='#'>合同范本</a> <br><a href='#'><font color=blue>图纸</font></a> <br><a href='#'><font color=blue>工具量清单</font></a> <br>");

			pe.setEnrollEndTime("<a href='#'><font color=blue>递交保证金</font></a><br> <a href='#'>递交资审文件</a><br> <a href='#'><font color=blue>递交招标文件</a></font>");

			pe.setEnrollStatus("<a href='#'><font color=blue>中标公示</font></a> <br> <a href='zbr_project_subway.do'><font color=blue>项目进展查看</a></font>");
			pe.setOperation(" <a href='#'><font color=blue>异议</font></a> <br> <a href='#'>资审文件确认</a><br><a href='#'><font color=blue>答疑文件</a></font>");

			peList.add(pe);
		}
		queryPage.setResult(peList);
		**/
		String jsonStr = "";
		try {
			//jsonStr = JsonUtils.toJsonStr(queryPage);
			response.getWriter().write(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 建设工程
	 * @param model
	 * @return
	 */
	public void getMyProject(Model model, int rows, int page, HttpServletResponse response) {
		PageSearchModel qm = new PageSearchModel();
		qm.setPageNo(page);
		qm.setPageSize(rows);
		/**
		Page queryPage = jsgcProjectService.queryPage(qm);
		List<JsgcProject> projectList = (List<JsgcProject>) queryPage.getResult();
		List<MyProject> peList = new ArrayList<MyProject>();
		MyProject pe = null;
		for (JsgcProject project : projectList) {
			pe = new MyProject();
			pe.setPackageCode("JS2012323-1");
			pe.setMessage("");
			pe.setBaseInfo("<font color=blue>标段名称：江苏连云县幸福蓝海国际影视工程-土建工程</font><br>开标时间：2013-5-12 9:00:00<br>开标地点：市第一开标室/评标地点：第二评标室");
			pe.setProjectName(project.getPrjName());
			pe.setOperation("<a href='#'>进入</a>");
			pe.setPackageStatus("投标人报名");
			peList.add(pe);
		}
		queryPage.setResult(peList);
		**/
		String jsonStr = "";
		try {
			//jsonStr = JsonUtils.toJsonStr(queryPage);
			response.getWriter().write(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
